$(function () {
    //科室的动态生成
    $.ajax({
        // ansyc: false,
        url: "/hospital/patient/register/office/get",
        type: "GET",
        // contentType:"application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            $("#office-tubiao").html("");
            // $("#office-tubiao").append("<option value=''>请选择科室</option>");
            $.each(data, function (index, ele) {
                $("#office-tubiao").append("<div class=\"tubiao\" id='"+ele.officeId+"'><span>"+ele.officeName+"</span></div>");
            });
        },
        error: function () {
            alert("数据加载失败！");
        }
    });
    //动态生成科室div的点击事件
    $("#office-tubiao").on("click", ".tubiao", function () {
        console.log($(this).attr("id"));
        var id = $(this).attr("id");
        //判断是否有权
        $.ajax({
                url: "/hospital/record/register/user",
                type: "GET",
                dataType: "json",
                success: function (data) {
                    if (data.ofcId == id || data.power == 1) {
                        // $("#console").load("dia-console.html?ofcId");
                        window.location.href="dia-console.html?ofcId="+id;
                    } else {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg('系统检测您不属于本科室，请重新认证或者提升权限', {
                                time: 2500, //1.5s后自动关闭
                            });
                        });
                    }
            },
            error: function () {
            alert("error");
        }
    });
});
})
;